<?php
	require_once('../class/SanPhamDAO.php');
	require_once('../class/LoaiSanPhamDAO.php');
	require_once('../session.inc');
	$maSP = $_REQUEST['maSanPham'];
	$stt = $_REQUEST['stt'];
	$tenSanPham = $_REQUEST['tenSanPham'];
	$donGiaBan = $_REQUEST['donGiaBan'];
	$donGiaGoc = $_REQUEST['donGiaGoc'];
	$maLoaiSP = $_REQUEST['maLoaiSP'];
	
	$sanPham = SanPhamDAO::LaySanPhamTheoMa($maSP, 0);
	$sanPhamDto = new SanPhamDAO();
	$sanPhamDto = $sanPham;
	$sanPhamDto->TenSanPham = $tenSanPham;
	$sanPhamDto->DonGiaGoc = $donGiaGoc;
	$sanPhamDto->DonGiaBan = $donGiaBan;
	$sanPhamDto->NgayCapNhat = date("Y-m-d");;
	$sanPhamDto->NguoiCapNhat = $_SESSION['IdUser'];
	$sanPhamDto->MaLoaiSP = $maLoaiSP;
	
	$result = SanPhamDAO::CapNhatThongTinSanPham($sanPhamDto);
	if($result)
	{
		$sanPham = SanPhamDAO::LaySanPhamTheoMa($maSP, 0);
		//$state = SanPhamDAO::CapNhatThongTinSanPham();
		$loaiSP = LoaiSanPhamDAO::LayLoaiSanPhamTheoMaLSP($sanPham->MaLoaiSP);
		$soLuongTon = $sanPham->SoLuong - SanPhamDAO::TinhSoLuongSanPhamDaMua($sanPham->Ma);
	
		//
		$btnDel = '<input name="btnXoaSP" type="button" value="Xóa" onclick="funcXoaSP('.$sanPham->Ma.')"/>';
		$btnUpd = '<input name="btnCapNhatSP" type="button" value="Cập nhật" onclick="funcCapNhatSP('.$sanPham->Ma .','.$loaiSP->MaGianHang.','.$stt.')"/>';
		$check_area = '<input name="chkItem" type="checkbox" onclick="updateList1();" value="'.$sanPham->Ma.'"/>';
		$res = ' <tr id="SP'.$sanPham->Ma.'">
					<td>
						'.$check_area.'
					</td>
					<td>'.$stt.'</td>
					<td>'.$sanPham->Ma.'</td>
					<td>'.$sanPham->TenSanPham.'</td>
					<td>'.$sanPham->DonGiaGoc.'</td>
					<td>'.$sanPham->DonGiaBan.'</td>
					<td>'.$soLuongTon.'</td>
					<td>'.$loaiSP->TenLoaiSP.'</td>
					<td>'.$btnUpd.'</td>
					<td>'.$btnDel.'</td>
				</tr>
					';
	echo $res;
	}
	else return;

?>